﻿@using SCMS.Resource
@model IEnumerable<SCMS.Model.MasterBudgetCategory>
<div class="partialViewCard">
<div class="partialViewCardHeader"><h3>@Resources.General_String_MasterBudgetCategories</h3></div>
<br />
@if (Model.Count() > 0)
{
    <!-- Since this view is rendered after any action, the status of our request is posted here. 1 = success, 0 = failure
         Common failure will be because of attempting to enter a category number or subline number that already exists-->
    <input type="hidden" id="actionStatus" value="@ViewBag.ActionStatus" />
    <input type="hidden" id="statusMsg" value="@ViewBag.StatusMsg" />
    <table width="98%" align="center" cellspacing="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th width="10%">
                @Resources.Budget_CategoryList_CategoryNo
            </th>
            <th width="75%" colspan="2">
                @Resources.Budget_CategoryList_CategoryName
            </th>            
            @if (UserContext.HasPermission(StandardPermissionProvider.MasterBudgetCategoriesManage))
            {
                <th width="15%">
                    @Resources.Global_String_Manage
                </th>
            }
        </tr>
    @foreach (var item in Model)
    {
        <tr class="grideven" style="font-weight: bold;">
            <td align="center">
                @Html.DisplayFor(modelItem => item.Number)
            </td>
            <td colspan="2">
                @Html.DisplayFor(modelItem => item.Description)
                @Ajax.ActionLink(Resources_frank.MasterBudget_MBCategories_AddNewGL, "AddNewGL", new { mbcId = item.Id }, new AjaxOptions
           {
               OnBegin = string.Format("ShowDialogue('" + Resources.Budget_EditLinkToMB_MBCategory + " {0} :: {1}')", item.Number, Resources_frank.MasterBudget_MBCategories_AddNewGL),
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
           }, new { style = "float: right;" }) 
            </td>            
            @if (UserContext.HasPermission(StandardPermissionProvider.MasterBudgetCategoriesManage))
            {
                <td align="center">
                    @Ajax.ActionLink(Resources.Global_String_Edit, "MBCIndex", new { id = "EditCategory" }, new AjaxOptions
               {
                   OnBegin = string.Format("ShowDialogue('{0} :: " + item.Number + "')", Resources.Global_String_Edit),
                   UpdateTargetId = "popup-page",
                   LoadingElementId = "popup-loading",
                   Url = Url.Action("EditCategory/" + item.Id.ToString())
               }) |
                    @Ajax.ActionLink(Resources.Global_String_Delete, "MBCIndex", new { id = "DeleteCategory" }, new AjaxOptions
               {
                   UpdateTargetId = "budgetDiv",
                   LoadingElementId = "loading",
                   Url = Url.Action("DeleteCategory/" + item.Id.ToString()),
                   Confirm = string.Format(Resources.Global_String_ConfirmDelete, item.Description)
               })
                </td>
            }
        </tr>
            if (item.GeneralLedgers.Count > 0)
            {
                foreach (var gl in item.GeneralLedgers.ToList())
                {
                    <tr class="gridodd">
                        <td>&nbsp;</td>
                        <td>
                            @gl.Code
                        </td>
                        <td>
                            @gl.Description
                        </td>            
                        @if (UserContext.HasPermission(StandardPermissionProvider.MasterBudgetCategoriesManage))
                        {
                            <td align="center">
                                @Ajax.ActionLink(Resources.Global_String_Edit, "EditGL", new { id = gl.Id }, new AjaxOptions
                           {
                               OnBegin = string.Format("ShowDialogue('{0} :: " + item.Number + "')", Resources.Global_String_Edit),
                               UpdateTargetId = "popup-page",
                               LoadingElementId = "popup-loading",
                               Url = Url.Action("EditGL/" + gl.Id)
                           }) |
                                @Ajax.ActionLink(Resources.Global_String_Delete, "DeleteGL", new { id = gl.Id }, new AjaxOptions
                           {
                               UpdateTargetId = "budgetDiv",
                               LoadingElementId = "loading",
                               Url = Url.Action("DeleteGL/" + gl.Id),
                               Confirm = string.Format(Resources.Global_String_ConfirmDelete, item.Description)
                           })
                            </td>
                        }
                    </tr>
                }
            }
        }
    </table>
}
@if (Model.Count() < 1)
{
    <table width="98%" align="center" cellspacing="0" cellpadding="5" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th width="5%">
                @Resources.Budget_CategoryList_CategoryNo
            </th>
            <th width="85%">
                @Resources.Budget_CategoryList_CategoryName
            </th>
            <th width="10%">
                @Resources.Global_String_Manage
            </th>
        </tr>
        <tr>
            <td colspan="3" align="center">
                @Ajax.ActionLink(Resources.Global_String_AddNew, "MBCIndex", new { id = "CreateCategory" }, new AjaxOptions
           {
               OnBegin = string.Format("ShowDialogue('{0}')", Resources.Budget_CategoryList_NewCategoryPopupHeader),
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action("CreateCategory/" + ViewBag.Id)
           })
            </td>
        </tr>
    </table>
}
<br />
</div>